package com.jxs.android.weiget;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import com.jxs.android.ges.R;

public class Bu_Filter_Page_List_View extends LinearLayout {
	static public interface Protocl_Loading_Listener {
		public void p_loadingData(int currentPage);
	}

	private Context context;

	private TextView title, seleted;
	private ListView listView;

	public Bu_Filter_Page_List_View(Context context) {
		this(context, null);
	}

	public Bu_Filter_Page_List_View(Context context, AttributeSet attrs) {
		super(context, attrs);
		this.context = context;
		initView();
		TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.WorkLogEditItem);
		String indexstr = a.getString(R.styleable.WorkLogEditItem_index);
		String contentstr = a.getString(R.styleable.WorkLogEditItem_content);
		seleted.setText(contentstr);
		title.setText(indexstr);
		a.recycle();

	}

	public void setTitle(String title) {
		this.title.setText(title);
	}

	public void setSelected(String title) {
		this.seleted.setText(title);
	}

	private void initView() {
		LayoutInflater.from(context).inflate(R.layout.bu_filter_page_list_view, this);
		title = (TextView) findViewById(R.id.select_title);
		seleted = (TextView) findViewById(R.id.seleted_tv);
		listView = (ListView) findViewById(R.id.common_listview);
	}

	public void setData(final List<Map<String, String>> list, final FiltedListItemListener listener) {
		SimpleAdapter adapter = new SimpleAdapter(context, list, R.layout.bu_filter_common_row, new String[] { "content" }, new int[] { R.id.row_content });
		listView.setAdapter(adapter);
		listView.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
				Map<String, String> items = list.get(position);
				listener.logic(items.get("id"), items.get("content"));
			}

		});
	}

	static public interface FiltedListItemListener {
		public void logic(String id, String content);
	}

}
